package com.ymy.thinking.in.spring.bean.factory;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * {@link PersonFactory} 默认实现
 *
 * @author Ringo
 * @date 2021/8/25 21:12
 */
public class DefaultPersonFactory implements PersonFactory, InitializingBean, DisposableBean {

    // 1: 基于 @PostConstructor 注解
    @PostConstruct
    public void init() {
        System.out.println("@PostConstruct 初始化Bean: PersonFactory init...");
    }

    // 2: 自定义初始化方法
    public void initPersonFactory() {
        System.out.println("自定义初始化方法: PersonFactory init...");
    }

    // 3: afterPropertiesSet 初始化
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("afterPropertiesSet 初始化方法: PersonFactory init...");
    }

    @PreDestroy
    public void destroyMethod() {
        System.out.println("@PreDestroy 在 DefaultPersonFactory 销毁之前执行...");
    }

    public void destroyPersonFactory() {
        System.out.println("自定义销毁方法 ...");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("实现 DisposableBean 接口 ...");
    }
}
